//一棵圣诞树记作根节点为 root 的二叉树，节点值为该位置装饰彩灯的颜色编号。请按照从 左 到 右 的顺序返回每一层彩灯编号。 
//
// 
//
// 示例 1： 
//
// 
//
// 
//输入：root = [8,17,21,18,null,null,6]
//输出：[8,17,21,18,6]
// 
//
// 
//
// 提示： 
//
// 
// 节点总数 <= 1000 
// 
//
// 
//
// Related Topics 树 广度优先搜索 二叉树 👍 315 👎 0


package LeetCode.editor.cn;


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

/**
 * @author ldltd
 * @date 2025-05-08 16:58:10
 * @description LCR 149.彩灯装饰记录 I
 
 */
 
public class CongShangDaoXiaDaYinErChaShuLcof {
    public static void main(String[] args) {
    //测试代码
    CongShangDaoXiaDaYinErChaShuLcof fun = new CongShangDaoXiaDaYinErChaShuLcof();
    Solution solution= fun.new Solution();
    
    }

//leetcode submit region begin(Prohibit modification and deletion)

//  Definition for a binary tree node.
  public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }

class Solution {
        //其实就是一个层次遍历
    public int[] decorateRecord(TreeNode root) {
        if(root==null) return new int[0];
        Deque<TreeNode> q=new ArrayDeque<>();
        q.offer(root);
        List<Integer> list=new ArrayList<>();
        while (!q.isEmpty()){
            int n=q.size();
            while (n>0){
                TreeNode poll = q.poll();
                list.add(poll.val);
                if(poll.left!=null) q.offer(poll.left);
                if(poll.right!=null) q.offer(poll.right);
                n--;
            }
        }
        int [] res=new int[list.size()];
        int idx=0;
        for (Integer i : list) {
            res[idx++]=i;
        }
        return res;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
